package com.cuijq.ms.strategy.v5;

import com.cuijq.ms.strategy.v5.impl.ConcurrentExternalSort;
import com.cuijq.ms.strategy.v5.impl.ExternalSort;
import com.cuijq.ms.strategy.v5.impl.MapReduceSort;
import com.cuijq.ms.strategy.v5.impl.QuickSort;
import java.util.HashMap;
import java.util.Map;

/**
 * @author by CuiJQ
 * @Classname SortAlgFactory
 * @Description SortAlgFactory Description
 * @Date 2021/5/29 9:36
 */
public class SortAlgFactory {

  private static final Map<String,ISortAlg> algs = new HashMap<>();

  static {
    algs.put("QuickSort", new QuickSort());
    algs.put("ExternalSort", new ExternalSort());
    algs.put("ConcurrentExternalSort", new ConcurrentExternalSort());
    algs.put("MapReduceSort", new MapReduceSort());
  }

  public static ISortAlg getSortAlg(String type) {
    if (type == null || type.isEmpty()) {
      throw new IllegalArgumentException("type should not be empty.");
    }
    return algs.get(type);
  }
}
